{extend name="common/base" /}
{block name="body"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">

                        <div class="layui-card-body">
                            {include file="user/userform" /}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="my_js"}
<script>
    layui.use(['element', 'admin', 'form', 'laydate', 'util'], function () {
        var element = layui.element
            , admin = layui.admin
            , util = layui.util
            , laydate = layui.laydate
            , form = layui.form;
        laydate.render({
            elem: '#birthday'
            , theme: '#20222A'
            , min: '1910-01-01'
            , value: '1993-01-01'
            , max: util.toDateString(new Date(), 'yyyy-MM-dd')
        });
        form.val('', {
            'birthday': '1993-01-01'
        });
        form.verify({
            user_login: function (value) {
                if(value == ''){
                    return '用户名不能为空';
                }
                var res = admin.isUserLogin(value);
                return res;
            }
            , user_email: function (value) {
                if (value != '') {
                    var res = admin.isEmail(value);
                    return res;
                }
            }
            , mobile: function (value) {
                if (value != '') {
                    var res = admin.isMobile(value);
                    return res;
                }
            }
            , user_pass: function (value) {
                var res = admin.isUserPass(value);
                return res;
            }
        });
        form.on('submit(formUser)', function (data) {
            data.field.status = data.field.status ? data.field.status : 0;
            admin.ajax('admin/user', data.field, function (data) {
                if (data.code == 1001) {
                    $('#layui-icon-refresh',parent.document).click();
                    layer.confirm(data.msg + ',是否继续添加?', {
                        icon: 3,
                        title: '提示',
                        btn: ['继续', '返回']
                    }, function (index) {
                        location.reload();
                    }, function () {
                        admin.closeSelf()
                    });
                } else {
                    layer.msg(data.msg);
                }
            });
        });
    });
</script>
{/block}